package com.freight.user.controller;

import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import com.freight.user.dto.DriverInfoDto;
import com.freight.user.entity.CompanyDriver;
import com.freight.user.entity.DriverUser;
import com.freight.user.service.CompanyDriverService;
import com.freight.user.service.DriverUserService;
import com.freight.user.vo.CompanyRelationshipVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(description = "货主司机关联接口")
@RequestMapping("/freight/companyDriver")
@Transactional
public class CompanyDriverController {

    @Autowired
    private CompanyDriverService companyDriverService;

    @RequestMapping(value = "/saveCompanyDriver", method = RequestMethod.POST)
    @ApiOperation(value = "保存货主司机管理信息-----")
    public Result<String> saveCompanyDriver(Long driverId, Long companyId) {
        companyDriverService.saveCompanyDriver(driverId, companyId);
        return ResultUtil.data("保存成功");
    }

    @RequestMapping(value = "/deleteCompanyDriver", method = RequestMethod.POST)
    @ApiOperation(value = "删除货主司机管理信息-----")
    public Result<String> deleteCompanyDriver(Long companyDriverId) {
        companyDriverService.deleteCompanyDriver(companyDriverId);
        return ResultUtil.data("操作成功");
    }

    @RequestMapping(value = "/getCompanyDriverList", method = RequestMethod.POST)
    @ApiOperation(value = "获取货主司机列表")
    public Result<List<CompanyRelationshipVo>> getCompanyDriverList(Long driverId) {
        List<CompanyRelationshipVo> list = companyDriverService.getCompanyDriverList(driverId);
        return new ResultUtil<List<CompanyRelationshipVo>>().setData(list);
    }

    @RequestMapping(value = "/getCompanyRelationshipList", method = RequestMethod.POST)
    @ApiOperation(value = "获取货主列表")
    public Result<List<CompanyRelationshipVo>> getCompanyRelationshipList(Long driverId) {
        List<CompanyRelationshipVo> list = companyDriverService.getCompanyRelationshipList(driverId);
        return new ResultUtil<List<CompanyRelationshipVo>>().setData(list);
    }
}
